<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('商品列表')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								<label>商品名称：</label>
								<input type="text" name="goodsName" />
							</li>
							<li>
								<label>所属店铺：</label>
								<select name="storeId" class="form-control">
									<option value="">全部</option>
									<option th:each="store : ${stores}" th:text="${store.storeName}"
										th:value="${store.storeId}"></option>
								</select>
							</li>
							<li>
								<label>商品状态：</label>
								<select name="status" class="form-control"
									th:with="type=${@dict.getType('shop_goods_status')}">
									<option value="">全部</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label>商品分类：</label>
								<div class="input-group" style="width: 200px;">
									<input id="categoryId" type="hidden" name="categoryId">
									<input id="categoryName" class="form-control" type="text"
										onclick="selectCategoryTree()"><span class="input-group-addon"
										onclick="selectCategoryTree()"><i class="fa fa-search"></i></span>
								</div>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
										class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
										class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:goods:add">
					<i class="fa fa-plus"></i> 发布商品
				</a>
				<a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
					shiro:hasPermission="system:goods:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:goods:export">
					<i class="fa fa-download"></i> 导出
				</a>

			</div>
			<div class="col-sm-12 select-table table-bordered">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<div id="previewLayer" style="display: none; padding: 10px;">
		<img src="" id="previewImg" style="max-width: 100%;" alt="">
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:goods:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:goods:remove')}]];
		var prefix = ctx + "shop/goods";
		var goodsType = [[${@dict.getType('shop_goods_type')}]];
		var specType = [[${@dict.getType('shop_spec_type')}]];
		$(function () {
			var options = {
				url: prefix + "/list",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				detailUrl: prefix + "/detail/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				modalName: "商品",
				columns: [{
					checkbox: true
				},
				{
					field: 'goodsId',
					title: '主键',
					visible: false
				},
				{
					title: '商品名称',
					align: 'left',
					formatter: function (value, row, index) {
						return $.table.tooltip(row.goodsName);
					}
				},
				{
					title: '图片',
					align: 'center',
					formatter: function (value, row, index) {
						return "<img src='" + row.image + "' style='height:36px;' target='_blank' title='点击查看' onclick='imagePreview(\"" + row.image + "\")'></img>";
					}
				},
				{
					field: 'goodsType',
					title: '商品类型',
					align: 'center',
					formatter: function (value, item, index) {
						return $.table.selectDictLabel(goodsType, value);
					}
				},
				{
					field: 'specType',
					title: '规格类型',
					align: 'center',
					formatter: function (value, item, index) {
						return $.table.selectDictLabel(specType, value);
					}
				},
				{
					field: 'categoryName',
					title: '商品分类',
					align: 'center'
				},
				{
					field: 'marketPrice',
					title: '原价',
					align: 'center'
				},
				{
					field: 'price',
					title: '售价',
					align: 'center'
				},
				{
					field: 'unit',
					title: '单位',
					align: 'center'
				},
				{
					field: 'stock',
					title: '库存',
					align: 'center'
				},
				{
					field: 'stock',
					title: '销量',
					align: 'center'
				},
				{
					visible: editFlag == 'hidden' ? false : true,
					title: '上架状态',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},
				{
					title: '操作',
					align: 'center',
					formatter: function (value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.goodsId + '\',1200,800)"><i class="fa fa-search"></i>详情</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>移除</a>');
						return actions.join('');
					}
				}]
			};
			$.table.init(options);
		});

		/*分类管理-新增-选择父分类树*/
		function selectCategoryTree() {
			var options = {
				title: '分类选择',
				width: "380",
				url: ctx + "shop/goods/category/selectCategoryTree/0/0",
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero) {
			var body = $.modal.getChildFrame(index);
			$("#categoryId").val(body.find('#treeId').val());
			$("#categoryName").val(body.find('#treeName').val());
			$.modal.close(index);
		}

		/* 上架状态显示 */
		function statusTools(row) {
			if (row.status == 0) {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="offline(\'' + row.goodsId + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="online(\'' + row.goodsId + '\')"></i> ';
			}
		}

		/* 商品-下架 */
		function offline(goodsId) {
			$.modal.confirm("确认要下架吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"goodsId": goodsId, "status": -1});
			})
		}

		/* 商品-上架 */
		function online(goodsId) {
			$.operate.post(prefix + "/changeStatus", {"goodsId": goodsId, "status": 0});
		}


		/** 预览轮播图片 */
		function imagePreview(url) {
			layer.photos({photos: {"data": [{"src": url}]}});
		}
	</script>
</body>

</html>